package com.bailing.permissions;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;

import com.bl.andr.permission.GrantResult;
import com.bl.andr.permission.PermissionManager;
import com.bl.andr.permission.Permissions;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        PermissionManager.getInstance().setNeedGrantFlag(true).setGrantResult(new GrantResult() {
            @Override
            public void onGrantedAll() {
                // 全部授权
                Toast.makeText(getApplicationContext(), "onGrantedAll", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDenied(String... permission) {
                //  用户点击 拒绝后（每次进入都会提示） 的处理逻辑
                Toast.makeText(getApplicationContext(), "onDenied", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onExplain(String... permission) {
                // 禁止后再次进入时 可以自定义弹窗说明该权限的处理方式也可继续请求权限
                Toast.makeText(getApplicationContext(), "onExplain", Toast.LENGTH_SHORT).show();
            }
        }).requestPermissions(this, Permissions.CAMERA, Permissions.ACCESS_COARSE_LOCATION);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        PermissionManager.getInstance()
                .onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
